#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include <sys/wait.h>

extern char** environ;

int main()
{
    char* const argv[]=
    {
        "mytest",
         NULL
    };

    char* const env[]={"Myvalue=1030",NULL};

    pid_t pid = fork();
    int exid;
    if(pid<0)
    {
        perror("fork");
        exit(-2);

    }
    else if(pid==0)
    {
        
        //child
       //char*path=getenv("PWD");
       //exid= execle("./test","./test",NULL, env);//*NULL一定记得
       //exid = execvpe("mytest",argv,env);//虽然是PATH，但是指定路径也行。
       //exid = execve("./mytest",argv,env);//系统调用，其余六个exec函数都是库函数，都是对execve的封装

        //能否调用以下脚本语言shell，python
        //execl("/usr/bin/bash", "bash", "test.sh", NULL);//需要解释器
        execl("/usr/bin/python3", "python3", "test.py", NULL);

        printf("execle failed exid:%d\n", exid);
        exit(exid); //-1

    }
    //father
    int status=0;
    pid_t rid=waitpid(pid,&status,0);
    if(rid>0)
    {
        printf("waitpid success pid:%d\n",rid);
        if(WIFEXITED(status))
        {
            printf("exec successfully\n");

        }
        else{
            printf("kill by sig:%d\n",status&0x7f);
        }
    }

    return 0;
}